<!--
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<section class="import-identity" fileDragDrop (fileDragDropFileAccepted)="fileAccepted($event)"
         (fileDragDropFileRejected)="fileRejected($event)"
         (fileDragDropDragOver)="fileDetected($event)" (fileDragDropDragLeave)="fileLeft($event)"
         [maxFileSize]="maxFileSize" [supportedFileTypes]="supportedFileTypes">
    <header class="drawer-header">
        <h1>Import Business Network Card</h1>
        <p>Drop a Composer Business Network (.card file) here to add it to My Business Networks:</p>

        <button class="icon modal-exit" (click)="activeDrawer.dismiss();">
            <svg class="ibm-icon" aria-hidden="true">
                <use xlink:href="#icon-close_new"></use>
            </svg>
        </button>
    </header>
    <section class="drawer-body">
        <div class="import-card" *ngIf="!identityCard">
            <file-importer (fileAccepted)="fileAccepted($event)" (fileRejected)="fileRejected($event)"
                           [expandInput]="expandInput"
                           [ngClass]="{'expandFile': expandInput}" [svgName]="'#icon-Card_Upload'"
                           [maxFileSize]="maxFileSize" [supportedFileTypes]="supportedFileTypes"></file-importer>
        </div>

        <div class="current-card" *ngIf="identityCard">
            <identity-card [identity]="identityCard" [preview]="true" [showDismissIcon]="true"
                           (onDismiss)="removeFile()">
            </identity-card>
        </div>
        <div class="card-name" *ngIf="identityCard">
            <label for="cardName"><h3>Give the imported card a name</h3></label>
            <input id="cardName" [ngClass]="{'error-underline': !cardNameValid}" type="text"
                   [ngModel]="cardName"
                   (ngModelChange)="setCardName($event)"
                   placeholder="eg. admin@{{identityCard.getBusinessNetworkName()}}">
            <div *ngIf="!cardNameValid" class="error-message">The card name must be unique</div>
        </div>
    </section>
    <footer class="drawer-footer">
        <button type="button" class="secondary" (click)="activeDrawer.dismiss();">
            <span>Cancel</span>
        </button>
        <button id="" type="button" id="importBtn" class="primary" (click)="import();" [disabled]="!identityCard || !cardNameValid">
            <span *ngIf="!importInProgress">Import</span>
            <div *ngIf="importInProgress" class="ibm-spinner-indeterminate small loop">
                <div class="loader">
                    <svg class="circular" viewBox="25 25 50 50">
                        <circle class="circle-path" cx="50" cy="50" r="20"/>
                    </svg>
                </div>
            </div>
        </button>
    </footer>
</section>
